package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * Created by void on 2020/4/12.
 */
@Controller
public class ThymeleafController {

    @GetMapping("/hi")
    public String hi(Locale locale, Model model){
        model.addAttribute("greeting", "hello!");

        Date date = new Date();
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
        String formattedDate = dateFormat.format(date);
        model.addAttribute("currentTime", formattedDate);
        return "hi";
    }

    @GetMapping("/index")
    public String tradeView(Locale locale, Model model){
        model.addAttribute("greeting", "hello!");

        Date date = new Date();
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
        String formattedDate = dateFormat.format(date);
        model.addAttribute("currentTime", formattedDate);
        return "index";
    }
}
